﻿using ETModel;
using System;
using UnityEngine;

namespace ETHotfix {
    public static class MsgHelper {



        public static Vector3[] GetVertices(this UnitInfo msg) {
            Vector3[] vertices = new Vector3[msg.ShapeVerticesXs.Count];
            for (int i = 0; i < vertices.Length; i++) {
                vertices[i] = new Vector3(msg.ShapeVerticesXs[i], msg.ShapeVerticesYs[i], msg.ShapeVerticesZs[i]);
            }
            return vertices;
        }
        public static int[] GetIndices(this UnitInfo msg) {
            int[] indices = new int[msg.ShapeIndices.Count];
            for (int i = 0; i < indices.Length; i++) {
                indices[i] = Convert.ToInt32(msg.ShapeIndices[i]);
            }
            return indices;
        }
        public static Vector3[] GetVertices(this GizmosMesh msg) {
            Vector3[] vertices = new Vector3[msg.Xs.Count];
            for (int i = 0; i < vertices.Length; i++) {
                vertices[i] = new Vector3(msg.Xs[i], msg.Ys[i], msg.Zs[i]);
            }
            return vertices;
        }
        public static int[] GetIndices(this GizmosMesh msg) {
            int[] indices = new int[msg.Indices.Count];
            for (int i = 0; i < indices.Length; i++) {
                indices[i] = Convert.ToInt32(msg.Indices[i]);
            }
            return indices;
        }


        #region IMsgMatrix4x4
        public static Matrix4x4 GetMatrix4x4(this ETModel.IMsgMatrix4x4 msg) {
            var matrix = new Matrix4x4();
            matrix.m00 = msg.M00;
            matrix.m01 = msg.M01;
            matrix.m02 = msg.M02;
            matrix.m03 = msg.M03;
            matrix.m10 = msg.M10;
            matrix.m11 = msg.M11;
            matrix.m12 = msg.M12;
            matrix.m13 = msg.M13;
            matrix.m20 = msg.M20;
            matrix.m21 = msg.M21;
            matrix.m22 = msg.M22;
            matrix.m23 = msg.M23;
            matrix.m30 = msg.M30;
            matrix.m31 = msg.M31;
            matrix.m32 = msg.M32;
            matrix.m33 = msg.M33;
            return matrix;
        }
        public static void SetMatrix4x4(this ETModel.IMsgMatrix4x4 msg, ref Matrix4x4 matrix) {
            msg.M00 = matrix.m00;
            msg.M01 = matrix.m01;
            msg.M02 = matrix.m02;
            msg.M03 = matrix.m03;
            msg.M10 = matrix.m10;
            msg.M11 = matrix.m11;
            msg.M12 = matrix.m12;
            msg.M13 = matrix.m13;
            msg.M20 = matrix.m20;
            msg.M21 = matrix.m21;
            msg.M22 = matrix.m22;
            msg.M23 = matrix.m23;
            msg.M30 = matrix.m30;
            msg.M31 = matrix.m31;
            msg.M32 = matrix.m32;
            msg.M33 = matrix.m33;
        }
        public static void SetMatrix4x4(this ETModel.IMsgMatrix4x4 msg, Matrix4x4 matrix) {
            SetMatrix4x4(msg, ref matrix);
        }

        public static Matrix4x4 GetMatrix4x4(this ETHotfix.IMsgMatrix4x4 msg) {
            var matrix = new Matrix4x4();
            matrix.m00 = msg.M00;
            matrix.m01 = msg.M01;
            matrix.m02 = msg.M02;
            matrix.m03 = msg.M03;
            matrix.m10 = msg.M10;
            matrix.m11 = msg.M11;
            matrix.m12 = msg.M12;
            matrix.m13 = msg.M13;
            matrix.m20 = msg.M20;
            matrix.m21 = msg.M21;
            matrix.m22 = msg.M22;
            matrix.m23 = msg.M23;
            matrix.m30 = msg.M30;
            matrix.m31 = msg.M31;
            matrix.m32 = msg.M32;
            matrix.m33 = msg.M33;
            return matrix;
        }
        public static void SetMatrix4x4(this ETHotfix.IMsgMatrix4x4 msg, ref Matrix4x4 matrix) {
            msg.M00 = matrix.m00;
            msg.M01 = matrix.m01;
            msg.M02 = matrix.m02;
            msg.M03 = matrix.m03;
            msg.M10 = matrix.m10;
            msg.M11 = matrix.m11;
            msg.M12 = matrix.m12;
            msg.M13 = matrix.m13;
            msg.M20 = matrix.m20;
            msg.M21 = matrix.m21;
            msg.M22 = matrix.m22;
            msg.M23 = matrix.m23;
            msg.M30 = matrix.m30;
            msg.M31 = matrix.m31;
            msg.M32 = matrix.m32;
            msg.M33 = matrix.m33;
        }
        public static void SetMatrix4x4(this ETHotfix.IMsgMatrix4x4 msg, Matrix4x4 matrix) {
            SetMatrix4x4(msg, ref matrix);
        }
        #endregion


        #region IMsgCenterPosition
        public static Vector3 GetCenterPosition(this ETModel.IMsgCenterPosition msg) {
            var pos = new Vector3();
            pos.x = msg.CenterPosX;
            pos.y = msg.CenterPosY;
            pos.z = msg.CenterPosZ;
            return pos;
        }
        public static void SetCenterPosition(this ETModel.IMsgCenterPosition msg, ref Vector3 pos) {
            msg.CenterPosX = pos.x;
            msg.CenterPosY = pos.y;
            msg.CenterPosZ = pos.z;
        }
        public static void SetCenterPosition(this ETModel.IMsgCenterPosition msg, Vector3 centerPos) {
            SetCenterPosition(msg, ref centerPos);
        }

        public static Vector3 GetCenterPosition(this ETHotfix.IMsgPosition msg) {
            var pos = new Vector3();
            pos.x = msg.CenterPosX;
            pos.y = msg.CenterPosY;
            pos.z = msg.CenterPosZ;
            return pos;
        }
        public static void SetCenterPosition(this ETHotfix.IMsgPosition msg, ref Vector3 pos) {
            msg.CenterPosX = pos.x;
            msg.CenterPosY = pos.y;
            msg.CenterPosZ = pos.z;
        }
        public static void SetCenterPosition(this ETHotfix.IMsgPosition msg, Vector3 matrix) {
            SetCenterPosition(msg, ref matrix);
        }
        #endregion

        #region IMsgScale
        public static Vector3 GetScale(this ETModel.IMsgScale msg) {
            var scale = new Vector3();
            scale.x = msg.ScaleX;
            scale.y = msg.ScaleY;
            scale.z = msg.ScaleZ;
            return scale;
        }
        public static void SetScale(this ETModel.IMsgScale msg, ref Vector3 scale) {
            msg.ScaleX = scale.x;
            msg.ScaleY = scale.y;
            msg.ScaleZ = scale.z;
        }
        public static void SetScale(this ETModel.IMsgScale msg, Vector3 matrix) {
            SetScale(msg, ref matrix);
        }

        public static Vector3 GetScale(this ETHotfix.IMsgScale msg) {
            var scale = new Vector3();
            scale.x = msg.ScaleX;
            scale.y = msg.ScaleY;
            scale.z = msg.ScaleZ;
            return scale;
        }
        public static void SetScale(this ETHotfix.IMsgScale msg, ref Vector3 scale) {
            msg.ScaleX = scale.x;
            msg.ScaleY = scale.y;
            msg.ScaleZ = scale.z;
        }
        public static void SetScale(this ETHotfix.IMsgScale msg, Vector3 matrix) {
            SetScale(msg, ref matrix);
        }
        #endregion

        #region IMsgRotation
        public static Quaternion GetRotation(this ETModel.IMsgRotation msg) {
            var rotation = new Quaternion();
            rotation.x = msg.RotationX;
            rotation.y = msg.RotationY;
            rotation.z = msg.RotationZ;
            rotation.w = msg.RotationW;
            return rotation;
        }
        public static void SetRotation(this ETModel.IMsgRotation msg, ref Quaternion rotation) {
            msg.RotationX = rotation.x;
            msg.RotationY = rotation.y;
            msg.RotationZ = rotation.z;
            msg.RotationW = rotation.w;
        }
        public static void SetRotation(this ETModel.IMsgRotation msg, Quaternion matrix) {
            SetRotation(msg, ref matrix);
        }

        public static Quaternion GetRotation(this ETHotfix.IMsgRotation msg) {
            var rotation = new Quaternion();
            rotation.x = msg.RotationX;
            rotation.y = msg.RotationY;
            rotation.z = msg.RotationZ;
            rotation.w = msg.RotationW;
            return rotation;
        }
        public static void SetRotation(this ETHotfix.IMsgRotation msg, ref Quaternion rotation) {
            msg.RotationX = rotation.x;
            msg.RotationY = rotation.y;
            msg.RotationZ = rotation.z;
            msg.RotationW = rotation.w;
        }
        public static void SetRotation(this ETHotfix.IMsgRotation msg, Quaternion matrix) {
            SetRotation(msg, ref matrix);
        }
        #endregion
    }
}
